home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 October / maximum-cd-2009-10.iso / DiscContents / Firefox Setup 3.5.exe / nonlocalized / chrome / toolkit.jar / content / mozapps / plugins / pluginInstallerWizard.js < prev    next >
Encoding:
JavaScript  |  2009-06-24  |  24.3 KB  |  698 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Plugin Finder Service.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * IBM Corporation.
  18.  * Portions created by the IBM Corporation are Copyright (C) 2004
  19.  * IBM Corporation. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Doron Rosenberg <doronr@us.ibm.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. function nsPluginInstallerWizard(){
  39.  
  40.   // create the request array
  41.   this.mPluginRequestArray = new Object();
  42.   // since the array is a hash, store the length
  43.   this.mPluginRequestArrayLength = 0;
  44.  
  45.   // create the plugin info array.
  46.   // a hash indexed by plugin id so we don't install 
  47.   // the same plugin more than once.
  48.   this.mPluginInfoArray = new Object();
  49.   this.mPluginInfoArrayLength = 0;
  50.  
  51.   // holds plugins we couldn't find
  52.   this.mPluginNotFoundArray = new Object();
  53.   this.mPluginNotFoundArrayLength = 0;
  54.  
  55.   // array holding pids of plugins that require a license
  56.   this.mPluginLicenseArray = new Array();
  57.  
  58.   // how many plugins are to be installed
  59.   this.pluginsToInstallNum = 0;
  60.  
  61.   this.mBrowser = null;
  62.   this.mSuccessfullPluginInstallation = 0;
  63.   this.mNeedsRestart = false;
  64.  
  65.   // arguments[0] is an array that contains two items:
  66.   //     an array of mimetypes that are missing
  67.   //     a reference to the browser that needs them, 
  68.   //        so we can notify which browser can be reloaded.
  69.  
  70.   if ("arguments" in window) {
  71.     for (var item in window.arguments[0].plugins){
  72.       this.mPluginRequestArray[window.arguments[0].plugins[item].mimetype] =
  73.         new nsPluginRequest(window.arguments[0].plugins[item]);
  74.  
  75.       this.mPluginRequestArrayLength++;
  76.     }
  77.  
  78.     this.mBrowser = window.arguments[0].browser;
  79.   }
  80.  
  81.   this.WSPluginCounter = 0;
  82.   this.licenseAcceptCounter = 0;
  83.  
  84.   this.prefBranch = null;
  85. }
  86.  
  87. nsPluginInstallerWizard.prototype.getPluginData = function (){
  88.   // for each mPluginRequestArray item, call the datasource
  89.   this.WSPluginCounter = 0;
  90.  
  91.   // initiate the datasource call
  92.   var rdfUpdater = new nsRDFItemUpdater(this.getOS(), this.getChromeLocale());
  93.  
  94.   for (var item in this.mPluginRequestArray) {
  95.     rdfUpdater.checkForPlugin(this.mPluginRequestArray[item]);
  96.   }
  97. }
  98.  
  99. // aPluginInfo is null if the datasource call failed, and pid is -1 if
  100. // no matching plugin was found.
  101. nsPluginInstallerWizard.prototype.pluginInfoReceived = function (aPluginRequestItem, aPluginInfo){
  102.   this.WSPluginCounter++;
  103.  
  104.   if (aPluginInfo && (aPluginInfo.pid != -1) ) {
  105.     // hash by id
  106.     this.mPluginInfoArray[aPluginInfo.pid] = new PluginInfo(aPluginInfo);
  107.     this.mPluginInfoArrayLength++;
  108.   } else {
  109.     this.mPluginNotFoundArray[aPluginRequestItem.mimetype] = aPluginRequestItem;
  110.     this.mPluginNotFoundArrayLength++;
  111.   }
  112.  
  113.   var progressMeter = document.getElementById("ws_request_progress");
  114.  
  115.   if (progressMeter.getAttribute("mode") == "undetermined")
  116.     progressMeter.setAttribute("mode", "determined");
  117.  
  118.   progressMeter.setAttribute("value",
  119.       ((this.WSPluginCounter / this.mPluginRequestArrayLength) * 100) + "%");
  120.  
  121.   if (this.WSPluginCounter == this.mPluginRequestArrayLength) {
  122.     // check if no plugins were found
  123.     if (this.mPluginInfoArrayLength == 0) {
  124.       this.advancePage("lastpage");
  125.     } else {
  126.       this.advancePage(null);
  127.     }
  128.   } else {
  129.     // process more.
  130.   }
  131. }
  132.  
  133. nsPluginInstallerWizard.prototype.showPluginList = function (){
  134.   var myPluginList = document.getElementById("pluginList");
  135.   var hasPluginWithInstallerUI = false;
  136.  
  137.   // clear children
  138.   for (var run = myPluginList.childNodes.length; run > 0; run--)
  139.     myPluginList.removeChild(myPluginList.childNodes.item(run));
  140.  
  141.   this.pluginsToInstallNum = 0;
  142.  
  143.   for (var pluginInfoItem in this.mPluginInfoArray){
  144.     // [plugin image] [Plugin_Name Plugin_Version]
  145.  
  146.     var pluginInfo = this.mPluginInfoArray[pluginInfoItem];
  147.  
  148.     // create the checkbox
  149.     var myCheckbox = document.createElement("checkbox");
  150.     myCheckbox.setAttribute("checked", "true");
  151.     myCheckbox.setAttribute("oncommand", "gPluginInstaller.toggleInstallPlugin('" + pluginInfo.pid + "', this)");
  152.     // XXXlocalize (nit)
  153.     myCheckbox.setAttribute("label", pluginInfo.name + " " + (pluginInfo.version ? pluginInfo.version : ""));
  154.     myCheckbox.setAttribute("src", pluginInfo.IconUrl);
  155.  
  156.     myPluginList.appendChild(myCheckbox);
  157.  
  158.     if (pluginInfo.InstallerShowsUI == "true")
  159.       hasPluginWithInstallerUI = true;
  160.  
  161.     // keep a running count of plugins the user wants to install
  162.     this.pluginsToInstallNum++;
  163.   }
  164.  
  165.   if (hasPluginWithInstallerUI)
  166.     document.getElementById("installerUI").hidden = false;
  167.  
  168.   this.canAdvance(true);
  169.   this.canRewind(false);
  170. }
  171.  
  172. nsPluginInstallerWizard.prototype.toggleInstallPlugin = function (aPid, aCheckbox) {
  173.   this.mPluginInfoArray[aPid].toBeInstalled = aCheckbox.checked;
  174.  
  175.   // if no plugins are checked, don't allow to advance
  176.   this.pluginsToInstallNum = 0;
  177.   for (var pluginInfoItem in this.mPluginInfoArray){
  178.     if (this.mPluginInfoArray[pluginInfoItem].toBeInstalled)
  179.       this.pluginsToInstallNum++;
  180.   }
  181.  
  182.   if (this.pluginsToInstallNum > 0)
  183.     this.canAdvance(true);
  184.   else
  185.     this.canAdvance(false);
  186. }
  187.  
  188. nsPluginInstallerWizard.prototype.canAdvance = function (aBool){
  189.   document.getElementById("plugin-installer-wizard").canAdvance = aBool;
  190. }
  191.  
  192. nsPluginInstallerWizard.prototype.canRewind = function (aBool){
  193.   document.getElementById("plugin-installer-wizard").canRewind = aBool;
  194. }
  195.  
  196. nsPluginInstallerWizard.prototype.canCancel = function (aBool){
  197.   document.documentElement.getButton("cancel").disabled = !aBool;
  198. }
  199.  
  200. nsPluginInstallerWizard.prototype.showLicenses = function (){
  201.   this.canAdvance(false);
  202.   this.canRewind(false);
  203.  
  204.   // only add if a license is provided and the plugin was selected to
  205.   // be installed
  206.   for (var pluginInfoItem in this.mPluginInfoArray){
  207.     var myPluginInfoItem = this.mPluginInfoArray[pluginInfoItem];
  208.     if (myPluginInfoItem.toBeInstalled && myPluginInfoItem.licenseURL && (myPluginInfoItem.licenseURL != ""))
  209.       this.mPluginLicenseArray.push(myPluginInfoItem.pid);
  210.   }
  211.  
  212.   if (this.mPluginLicenseArray.length == 0) {
  213.     // no plugins require licenses
  214.     this.advancePage(null);
  215.   } else {
  216.     this.licenseAcceptCounter = 0;
  217.  
  218.     // add a nsIWebProgress listener to the license iframe.
  219.     var docShell = document.getElementById("licenseIFrame").docShell;
  220.     var iiReq = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  221.     var webProgress = iiReq.getInterface(Components.interfaces.nsIWebProgress);
  222.     webProgress.addProgressListener(gPluginInstaller.progressListener,
  223.                                     Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  224.  
  225.     this.showLicense();
  226.   }
  227. }
  228.  
  229. nsPluginInstallerWizard.prototype.enableNext = function (){
  230.   // if only one plugin exists, don't enable the next button until
  231.   // the license is accepted
  232.   if (gPluginInstaller.pluginsToInstallNum > 1)
  233.     gPluginInstaller.canAdvance(true);
  234.  
  235.   document.getElementById("licenseRadioGroup1").disabled = false;
  236.   document.getElementById("licenseRadioGroup2").disabled = false;
  237. }
  238.  
  239. const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
  240. nsPluginInstallerWizard.prototype.progressListener = {
  241.   onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
  242.   {
  243.     if ((aStateFlags & nsIWebProgressListener.STATE_STOP) &&
  244.        (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK)) {
  245.       // iframe loaded
  246.       gPluginInstaller.enableNext();
  247.     }
  248.   },
  249.  
  250.   onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress,
  251.                               aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
  252.   {},
  253.   onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
  254.   {},
  255.  
  256.   QueryInterface : function(aIID)
  257.   {
  258.      if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  259.          aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  260.          aIID.equals(Components.interfaces.nsISupports))
  261.        return this;
  262.      throw Components.results.NS_NOINTERFACE;
  263.    }
  264. }
  265.  
  266. nsPluginInstallerWizard.prototype.showLicense = function (){
  267.   var pluginInfo = this.mPluginInfoArray[this.mPluginLicenseArray[this.licenseAcceptCounter]];
  268.  
  269.   this.canAdvance(false);
  270.  
  271.   var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
  272.   document.getElementById("licenseIFrame").webNavigation.loadURI(pluginInfo.licenseURL, loadFlags, null, null, null);
  273.  
  274.   document.getElementById("pluginLicenseLabel").firstChild.nodeValue = 
  275.     this.getFormattedString("pluginLicenseAgreement.label", [pluginInfo.name]);
  276.  
  277.   document.getElementById("licenseRadioGroup1").disabled = true;
  278.   document.getElementById("licenseRadioGroup2").disabled = true;
  279.   document.getElementById("licenseRadioGroup").selectedIndex = 
  280.     pluginInfo.licenseAccepted ? 0 : 1;
  281. }
  282.  
  283. nsPluginInstallerWizard.prototype.showNextLicense = function (){
  284.   var rv = true;
  285.  
  286.   if (this.mPluginLicenseArray.length > 0) {
  287.     this.storeLicenseRadioGroup();
  288.  
  289.     this.licenseAcceptCounter++;
  290.  
  291.     if (this.licenseAcceptCounter < this.mPluginLicenseArray.length) {
  292.       this.showLicense();
  293.  
  294.       rv = false;
  295.       this.canRewind(true);
  296.     }
  297.   }
  298.  
  299.   return rv;
  300. }
  301.  
  302. nsPluginInstallerWizard.prototype.showPreviousLicense = function (){
  303.   this.storeLicenseRadioGroup();
  304.   this.licenseAcceptCounter--;
  305.  
  306.   if (this.licenseAcceptCounter > 0)
  307.     this.canRewind(true);
  308.   else
  309.     this.canRewind(false);
  310.  
  311.   this.showLicense();
  312.   
  313.   // don't allow to return from the license screens
  314.   return false;
  315. }
  316.  
  317. nsPluginInstallerWizard.prototype.storeLicenseRadioGroup = function (){
  318.   var pluginInfo = this.mPluginInfoArray[this.mPluginLicenseArray[this.licenseAcceptCounter]];
  319.   pluginInfo.licenseAccepted = !document.getElementById("licenseRadioGroup").selectedIndex;
  320. }
  321.  
  322. nsPluginInstallerWizard.prototype.licenseRadioGroupChange = function(aAccepted) {
  323.   // only if one plugin is to be installed should selection change the next button
  324.   if (this.pluginsToInstallNum == 1)
  325.     this.canAdvance(aAccepted);
  326. }
  327.  
  328. nsPluginInstallerWizard.prototype.advancePage = function (aPageId){
  329.   this.canAdvance(true);
  330.   document.getElementById("plugin-installer-wizard").advance(aPageId);
  331. }
  332.  
  333. nsPluginInstallerWizard.prototype.startPluginInstallation = function (){
  334.   this.canAdvance(false);
  335.   this.canRewind(false);
  336.  
  337.   var installerPlugins = [];
  338.   var xpiPlugins = [];
  339.  
  340.   for (var pluginInfoItem in this.mPluginInfoArray){
  341.     var pluginItem = this.mPluginInfoArray[pluginInfoItem];
  342.  
  343.     if (pluginItem.toBeInstalled && pluginItem.licenseAccepted) {
  344.       if (pluginItem.InstallerLocation)
  345.         installerPlugins.push(pluginItem);
  346.       else if (pluginItem.XPILocation)
  347.         xpiPlugins.push(pluginItem);
  348.     }
  349.   }
  350.  
  351.   if (installerPlugins.length > 0 || xpiPlugins.length > 0)
  352.     PluginInstallService.startPluginInstallation(installerPlugins,
  353.                                                  xpiPlugins);
  354.   else
  355.     this.advancePage(null);
  356. }
  357.  
  358. /*
  359.   0    starting download
  360.   1    download finished
  361.   2    starting installation
  362.   3    finished installation
  363.   4    all done
  364. */
  365. nsPluginInstallerWizard.prototype.pluginInstallationProgress = function (aPid, aProgress, aError) {
  366.  
  367.   var statMsg = null;
  368.   var pluginInfo = gPluginInstaller.mPluginInfoArray[aPid];
  369.  
  370.   switch (aProgress) {
  371.  
  372.     case 0:
  373.       statMsg = this.getFormattedString("pluginInstallation.download.start", [pluginInfo.name]);
  374.       break;
  375.  
  376.     case 1:
  377.       statMsg = this.getFormattedString("pluginInstallation.download.finish", [pluginInfo.name]);
  378.       break;
  379.  
  380.     case 2:
  381.       statMsg = this.getFormattedString("pluginInstallation.install.start", [pluginInfo.name]);
  382.       var progressElm = document.getElementById("plugin_install_progress");
  383.       progressElm.setAttribute("mode", "undetermined");
  384.       break;
  385.  
  386.     case 3:
  387.       if (aError) {
  388.         statMsg = this.getFormattedString("pluginInstallation.install.error", [pluginInfo.name, aError]);
  389.         pluginInfo.error = aError;
  390.       } else {
  391.         statMsg = this.getFormattedString("pluginInstallation.install.finish", [pluginInfo.name]);
  392.         pluginInfo.error = null;
  393.       }
  394.       break;
  395.  
  396.     case 4:
  397.       statMsg = this.getString("pluginInstallation.complete");
  398.       break;
  399.   }
  400.  
  401.   if (statMsg)
  402.     document.getElementById("plugin_install_progress_message").value = statMsg;
  403.  
  404.   if (aProgress == 4) {
  405.     this.advancePage(null);
  406.   }
  407. }
  408.  
  409. nsPluginInstallerWizard.prototype.pluginInstallationProgressMeter = function (aPid, aValue, aMaxValue){
  410.   var progressElm = document.getElementById("plugin_install_progress");
  411.  
  412.   if (progressElm.getAttribute("mode") == "undetermined")
  413.     progressElm.setAttribute("mode", "determined");
  414.   
  415.   progressElm.setAttribute("value", Math.ceil((aValue / aMaxValue) * 100) + "%")
  416. }
  417.  
  418. nsPluginInstallerWizard.prototype.addPluginResultRow = function (aImgSrc, aName, aNameTooltip, aStatus, aStatusTooltip, aManualUrl){
  419.   var myRows = document.getElementById("pluginResultList");
  420.  
  421.   var myRow = document.createElement("row");
  422.   myRow.setAttribute("align", "center");
  423.  
  424.   // create the image
  425.   var myImage = document.createElement("image");
  426.   myImage.setAttribute("src", aImgSrc);
  427.   myImage.setAttribute("height", "16px");
  428.   myImage.setAttribute("width", "16px");
  429.   myRow.appendChild(myImage)
  430.  
  431.   // create the labels
  432.   var myLabel = document.createElement("label");
  433.   myLabel.setAttribute("value", aName);
  434.   if (aNameTooltip)
  435.     myLabel.setAttribute("tooltiptext", aNameTooltip);
  436.   myRow.appendChild(myLabel);
  437.  
  438.   if (aStatus) {
  439.     myLabel = document.createElement("label");
  440.     myLabel.setAttribute("value", aStatus);
  441.     myRow.appendChild(myLabel);
  442.   }
  443.  
  444.   // manual install
  445.   if (aManualUrl) {
  446.     var myButton = document.createElement("button");
  447.  
  448.     var manualInstallLabel = this.getString("pluginInstallationSummary.manualInstall.label");
  449.     var manualInstallTooltip = this.getString("pluginInstallationSummary.manualInstall.tooltip");
  450.  
  451.     myButton.setAttribute("label", manualInstallLabel);
  452.     myButton.setAttribute("tooltiptext", manualInstallTooltip);
  453.  
  454.     myRow.appendChild(myButton);
  455.  
  456.     // XXX: XUL sucks, need to add the listener after it got added into the document
  457.     if (aManualUrl)
  458.       myButton.addEventListener("command", function() { gPluginInstaller.loadURL(aManualUrl) }, false);
  459.   }
  460.  
  461.   myRows.appendChild(myRow);
  462. }
  463.  
  464. nsPluginInstallerWizard.prototype.showPluginResults = function (){
  465.   var notInstalledList = "?action=missingplugins";
  466.   var myRows = document.getElementById("pluginResultList");
  467.  
  468.   // clear children
  469.   for (var run = myRows.childNodes.length; run--; run > 0)
  470.     myRows.removeChild(myRows.childNodes.item(run));
  471.  
  472.   for (var pluginInfoItem in this.mPluginInfoArray){
  473.     // [plugin image] [Plugin_Name Plugin_Version] [Success/Failed] [Manual Install (if Failed)]
  474.  
  475.     var myPluginItem = this.mPluginInfoArray[pluginInfoItem];
  476.  
  477.     if (myPluginItem.toBeInstalled) {
  478.       var statusMsg;
  479.       var statusTooltip;
  480.       if (myPluginItem.error){
  481.         statusMsg = this.getString("pluginInstallationSummary.failed");
  482.         statusTooltip = myPluginItem.error;
  483.         notInstalledList += "&mimetype=" + pluginInfoItem;
  484.       } else if (!myPluginItem.licenseAccepted) {
  485.         statusMsg = this.getString("pluginInstallationSummary.licenseNotAccepted");
  486.       } else if (!myPluginItem.XPILocation && !myPluginItem.InstallerLocation) {
  487.         statusMsg = this.getString("pluginInstallationSummary.notAvailable");
  488.         notInstalledList += "&mimetype=" + pluginInfoItem;
  489.       } else {
  490.         this.mSuccessfullPluginInstallation++;
  491.         statusMsg = this.getString("pluginInstallationSummary.success");
  492.  
  493.         // only check needsRestart if the plugin was successfully installed.
  494.         if (myPluginItem.needsRestart)
  495.           this.mNeedsRestart = true;
  496.       }
  497.  
  498.       // manual url - either returned from the webservice or the pluginspage attribute
  499.       var manualUrl;
  500.       if ((myPluginItem.error || (!myPluginItem.XPILocation && !myPluginItem.InstallerLocation)) &&
  501.           (myPluginItem.manualInstallationURL || this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage)){
  502.         manualUrl = myPluginItem.manualInstallationURL ? myPluginItem.manualInstallationURL : this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage;
  503.       }
  504.  
  505.       this.addPluginResultRow(
  506.           myPluginItem.IconUrl, 
  507.           myPluginItem.name + " " + (myPluginItem.version ? myPluginItem.version : ""),
  508.           null,
  509.           statusMsg, 
  510.           statusTooltip,
  511.           manualUrl);
  512.     }
  513.   }
  514.  
  515.   // handle plugins we couldn't find
  516.   for (pluginInfoItem in this.mPluginNotFoundArray){
  517.     var pluginRequest = this.mPluginNotFoundArray[pluginInfoItem];
  518.  
  519.     // if there is a pluginspage, show UI
  520.     if (pluginRequest.pluginsPage) {
  521.       this.addPluginResultRow(
  522.           "",
  523.           this.getFormattedString("pluginInstallation.unknownPlugin", [pluginInfoItem]),
  524.           null,
  525.           null,
  526.           null,
  527.           pluginRequest.pluginsPage);
  528.     }
  529.  
  530.     notInstalledList += "&mimetype=" + pluginInfoItem;
  531.   }
  532.  
  533.   // no plugins were found, so change the description of the final page.
  534.   if (this.mPluginInfoArrayLength == 0) {
  535.     var noPluginsFound = this.getString("pluginInstallation.noPluginsFound");
  536.     document.getElementById("pluginSummaryDescription").setAttribute("value", noPluginsFound);
  537.   } else if (this.mSuccessfullPluginInstallation == 0) {
  538.     // plugins found, but none were installed.
  539.     var noPluginsInstalled = this.getString("pluginInstallation.noPluginsInstalled");
  540.     document.getElementById("pluginSummaryDescription").setAttribute("value", noPluginsInstalled);
  541.   }
  542.  
  543.   document.getElementById("pluginSummaryRestartNeeded").hidden = !this.mNeedsRestart;
  544.  
  545.   var app = Components.classes["@mozilla.org/xre/app-info;1"]
  546.                       .getService(Components.interfaces.nsIXULAppInfo);
  547.  
  548.   // set the get more info link to contain the mimetypes we couldn't install.
  549.   notInstalledList +=
  550.     "&appID=" + app.ID +
  551.     "&appVersion=" + app.platformBuildID +
  552.     "&clientOS=" + this.getOS() +
  553.     "&chromeLocale=" + this.getChromeLocale() +
  554.     "&appRelease=" + app.version;
  555.  
  556.   document.getElementById("moreInfoLink").addEventListener("click", function() { gPluginInstaller.loadURL("https://pfs.mozilla.org/plugins/" + notInstalledList) }, false);
  557.  
  558.   if (this.mNeedsRestart) {
  559.     var cancel = document.getElementById("plugin-installer-wizard").getButton("cancel");
  560.     cancel.label = this.getString("pluginInstallation.close.label");
  561.     cancel.accessKey = this.getString("pluginInstallation.close.accesskey");
  562.     var finish = document.getElementById("plugin-installer-wizard").getButton("finish");
  563.     finish.label = this.getFormattedString("pluginInstallation.restart.label", [app.name]);
  564.     finish.accessKey = this.getString("pluginInstallation.restart.accesskey");
  565.     this.canCancel(true);
  566.   }
  567.   else {
  568.     this.canCancel(false);
  569.   }
  570.   this.canAdvance(true);
  571.   this.canRewind(false);
  572. }
  573.  
  574. nsPluginInstallerWizard.prototype.loadURL = function (aUrl){
  575.   // Check if the page where the plugin came from can load aUrl before
  576.   // loading it, and do *not* allow loading URIs that would inherit our
  577.   // principal.
  578.   
  579.   var pluginPagePrincipal =
  580.     window.opener.content.document.nodePrincipal;
  581.  
  582.   const nsIScriptSecurityManager =
  583.     Components.interfaces.nsIScriptSecurityManager;
  584.   var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
  585.                          .getService(nsIScriptSecurityManager);
  586.  
  587.   secMan.checkLoadURIStrWithPrincipal(pluginPagePrincipal, aUrl,
  588.     nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
  589.  
  590.   window.opener.open(aUrl);
  591. }
  592.  
  593. nsPluginInstallerWizard.prototype.getString = function (aName){
  594.   return document.getElementById("pluginWizardString").getString(aName);
  595. }
  596.  
  597. nsPluginInstallerWizard.prototype.getFormattedString = function (aName, aArray){
  598.   return document.getElementById("pluginWizardString").getFormattedString(aName, aArray);
  599. }
  600.  
  601. nsPluginInstallerWizard.prototype.getOS = function (){
  602.   var httpService = Components.classes["@mozilla.org/network/protocol;1?name=http"]
  603.                               .getService(Components.interfaces.nsIHttpProtocolHandler);
  604.   return httpService.oscpu;
  605. }
  606.  
  607. nsPluginInstallerWizard.prototype.getChromeLocale = function (){
  608.   var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
  609.                             .getService(Components.interfaces.nsIXULChromeRegistry);
  610.   return chromeReg.getSelectedLocale("global");
  611. }
  612.  
  613. nsPluginInstallerWizard.prototype.getPrefBranch = function (){
  614.   if (!this.prefBranch)
  615.     this.prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  616.                                 .getService(Components.interfaces.nsIPrefBranch);
  617.   return this.prefBranch;
  618. }
  619. function nsPluginRequest(aPlugRequest){
  620.   this.mimetype = encodeURI(aPlugRequest.mimetype);
  621.   this.pluginsPage = aPlugRequest.pluginsPage;
  622. }
  623.  
  624. function PluginInfo(aResult) {
  625.   this.name = aResult.name;
  626.   this.pid = aResult.pid;
  627.   this.version = aResult.version;
  628.   this.IconUrl = aResult.IconUrl;
  629.   this.InstallerLocation = aResult.InstallerLocation;
  630.   this.InstallerHash = aResult.InstallerHash;
  631.   this.XPILocation = aResult.XPILocation;
  632.   this.XPIHash = aResult.XPIHash;
  633.   this.InstallerShowsUI = aResult.InstallerShowsUI;
  634.   this.manualInstallationURL = aResult.manualInstallationURL;
  635.   this.requestedMimetype = aResult.requestedMimetype;
  636.   this.licenseURL = aResult.licenseURL;
  637.   this.needsRestart = (aResult.needsRestart == "true");
  638.  
  639.   this.error = null;
  640.   this.toBeInstalled = true;
  641.  
  642.   // no license provided, make it accepted
  643.   this.licenseAccepted = this.licenseURL ? false : true;
  644. }
  645.  
  646. var gPluginInstaller;
  647.  
  648. function wizardInit(){
  649.   gPluginInstaller = new nsPluginInstallerWizard();
  650.   gPluginInstaller.canAdvance(false);
  651.   gPluginInstaller.getPluginData();
  652. }
  653.  
  654. function wizardFinish(){
  655.   if (gPluginInstaller.mNeedsRestart) {
  656.     // Notify all windows that an application quit has been requested.
  657.     var os = Components.classes["@mozilla.org/observer-service;1"]
  658.                        .getService(Components.interfaces.nsIObserverService);
  659.     var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  660.                                .createInstance(Components.interfaces.nsISupportsPRBool);
  661.     os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
  662.  
  663.     // Something aborted the quit process.
  664.     if (!cancelQuit.data) {
  665.       var nsIAppStartup = Components.interfaces.nsIAppStartup;
  666.       var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
  667.                                  .getService(nsIAppStartup);
  668.       appStartup.quit(nsIAppStartup.eAttemptQuit | nsIAppStartup.eRestart);
  669.       return true;
  670.     }
  671.   }
  672.  
  673.   // don't refresh if no plugins were found or installed
  674.   if ((gPluginInstaller.mSuccessfullPluginInstallation > 0) &&
  675.       (gPluginInstaller.mPluginInfoArray.length != 0)) {
  676.  
  677.     // reload plugins so JS detection works immediately
  678.     try {
  679.       var pm = Components.classes["@mozilla.org/plugin/manager;1"]
  680.                          .getService(Components.interfaces.nsIPluginManager);
  681.       pm.reloadPlugins(false);
  682.     }
  683.     catch (e) {
  684.       // reloadPlugins throws an exception if there were no plugins to load
  685.     }
  686.  
  687.     if (gPluginInstaller.mBrowser) {
  688.       // notify listeners that a plugin is installed,
  689.       // so that they can reset the UI and update the browser.
  690.       var event = document.createEvent("Events");
  691.       event.initEvent("NewPluginInstalled", true, true);
  692.       gPluginInstaller.mBrowser.dispatchEvent(event);
  693.     }
  694.   }
  695.  
  696.   return true;
  697. }
  698.